package com.hunttown.mes.convert;

import com.google.common.collect.Lists;
import com.hunttown.mes.common.utils.BeanUtils;
import com.hunttown.mes.domain.MesSaleExpress;
import com.hunttown.mes.rpc.exception.ConvertException;
import com.hunttown.mes.rpc.domain.MesSaleExpressDTO;
import com.hunttown.mes.rpc.domain.enums.ErrorCode;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;

/**
 * created by wangjunfu on 2022-03-30 15:34:47
 */
public class MesSaleExpressConverts {

    private static Logger LOG = LoggerFactory.getLogger(MesSaleExpressConverts.class);

    public static List<MesSaleExpressDTO> convert(List<MesSaleExpress> mesSaleExpressList) {
        if (CollectionUtils.isEmpty(mesSaleExpressList)) {
            return Collections.EMPTY_LIST;
        }

        List<MesSaleExpressDTO> mesSaleExpressListResult = Lists.newArrayList();
        for (MesSaleExpress mesSaleExpress : mesSaleExpressList) {
            mesSaleExpressListResult.add(convert(mesSaleExpress));
        }
        return mesSaleExpressListResult;
    }

    public static MesSaleExpressDTO convert(MesSaleExpress mesSaleExpress) {
        try {
            return BeanUtils.copy(mesSaleExpress, MesSaleExpressDTO.class);
        } catch (Exception e) {
            LOG.error("MesSaleExpress到MesSaleExpressDTO转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "MesSaleExpress到MesSaleExpressDTO转换失败", e);
        }
    }

    public static MesSaleExpress convert(MesSaleExpressDTO mesSaleExpressDTO) {
        try {
            return BeanUtils.copy(mesSaleExpressDTO, MesSaleExpress.class);
        } catch (Exception e) {
            LOG.error("MesSaleExpressDTO到MesSaleExpress转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "MesSaleExpressDTO到MesSaleExpress转换失败", e);
        }
    }
}